package com.hc.model.code04.test4;

/**
 * @version v1.0
 * @ClassName: Handler
 * @Description: 抽象处理者对象
 * @Author: HC
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 该领导处理的请求天数区间
    private int numStart;
    private int numEnd;

    // 声明后继者（声明上级领导）
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    // 设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 处理请求
    protected abstract void handleLeave(LeaveRequest leave);

    // 提交请求
    public final void submit(LeaveRequest leave) {
        // 处理请求
        handleLeave(leave);
        // 判断是否可以处理该请求
        if (this.nextHandler != null && leave.getNum() > this.numEnd) {
            this.nextHandler.submit(leave);
        } else {
            System.out.println("流程结束");
        }
    }
}
